home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 2 / AACD 2.iso / AACD / Programming / fpc / compiler / m68k.pas < prev    next >
Pascal/Delphi Source File  |  1998-09-24  |  61KB  |  1,738 lines

  1. {
  2.     $Id: m68k.pas,v 1.1.1.1.2.1 1998/08/13 17:41:24 florian Exp $
  3.     Copyright (c) 1995-98 by Florian Klaempfl, Carl Eric Codere
  4.  
  5.     This unit implements an types and classes specific for the
  6.     MC68000/MC68020
  7.  
  8.     This program is free software; you can redistribute it and/or modify
  9.     it under the terms of the GNU General Public License as published by
  10.     the Free Software Foundation; either version 2 of the License, or
  11.     (at your option) any later version.
  12.  
  13.     This program is distributed in the hope that it will be useful,
  14.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.     GNU General Public License for more details.
  17.  
  18.     You should have received a copy of the GNU General Public License
  19.     along with this program; if not, write to the Free Software
  20.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  
  22.  ****************************************************************************
  23. }
  24. unit m68k;
  25.  
  26.   interface
  27.  
  28.     uses
  29.        strings,systems,cobjects,globals,aasm,verbose;
  30.  
  31.     const
  32.       { if real fpu is used }
  33.       { otherwise maps to   }
  34.       { s32real.            }
  35.       extended_size = 12;
  36.  
  37.  
  38.     type
  39.     {  warning: CPU32 opcodes are not fully compatible with the MC68020. }
  40.        { 68000 only opcodes }
  41.        tasmop = (A_ABCD,
  42.          A_ADD,A_ADDA,A_ADDI,A_ADDQ,A_ADDX,A_AND,A_ANDI,
  43.          A_ASL,A_ASR,A_BCC,A_BCS,A_BEQ,A_BGE,A_BGT,A_BHI,
  44.          A_BLE,A_BLS,A_BLT,A_BMI,A_BNE,A_BPL,A_BVC,A_BVS,
  45.          A_BCHG,A_BCLR,A_BRA,A_BSET,A_BSR,A_BTST,A_CHK,
  46.          A_CLR,A_CMP,A_CMPA,A_CMPI,A_CMPM,A_DBCC,A_DBCS,A_DBEQ,A_DBGE,
  47.          A_DBGT,A_DBHI,A_DBLE,A_DBLS,A_DBLT,A_DBMI,A_DBNE,A_DBRA,
  48.          A_DBPL,A_DBT,A_DBVC,A_DBVS,A_DBF,A_DIVS,A_DIVU,
  49.          A_EOR,A_EORI,A_EXG,A_ILLEGAL,A_EXT,A_JMP,A_JSR,
  50.          A_LEA,A_LINK,A_LSL,A_LSR,A_MOVE,A_MOVEA,A_MOVEI,A_MOVEQ,
  51.          A_MOVEM,A_MOVEP,A_MULS,A_MULU,A_NBCD,A_NEG,A_NEGX,
  52.          A_NOP,A_NOT,A_OR,A_ORI,A_PEA,A_ROL,A_ROR,A_ROXL,
  53.          A_ROXR,A_RTR,A_RTS,A_SBCD,A_SCC,A_SCS,A_SEQ,A_SGE,
  54.          A_SGT,A_SHI,A_SLE,A_SLS,A_SLT,A_SMI,A_SNE,
  55.          A_SPL,A_ST,A_SVC,A_SVS,A_SF,A_SUB,A_SUBA,A_SUBI,A_SUBQ,
  56.          A_SUBX,A_SWAP,A_TAS,A_TRAP,A_TRAPV,A_TST,A_UNLK,
  57.          A_RTE,A_RESET,A_STOP,
  58.          { MC68010 instructions }
  59.          A_BKPT,A_MOVEC,A_MOVES,A_RTD,
  60.          { MC68020 instructions }
  61.          A_BFCHG,A_BFCLR,A_BFEXTS,A_BFEXTU,A_BFFFO,
  62.          A_BFINS,A_BFSET,A_BFTST,A_CALLM,A_CAS,A_CAS2,
  63.          A_CHK2,A_CMP2,A_DIVSL,A_DIVUL,A_EXTB,A_PACK,A_RTM,
  64.          A_TRAPCC,A_TRACS,A_TRAPEQ,A_TRAPF,A_TRAPGE,A_TRAPGT,
  65.          A_TRAPHI,A_TRAPLE,A_TRAPLS,A_TRAPLT,A_TRAPMI,A_TRAPNE,
  66.          A_TRAPPL,A_TRAPT,A_TRAPVC,A_TRAPVS,A_UNPK,
  67.          { FPU Processor instructions - directly supported only. }
  68.          { IEEE aware and misc. condition codes not supported   }
  69.          A_FABS,A_FADD,
  70.          A_FBEQ,A_FBNE,A_FBNGT,A_FBGT,A_FBGE,A_FBNGE,
  71.          A_FBLT,A_FBNLT,A_FBLE,A_FBGL,A_FBNGL,A_FBGLE,A_FBNGLE,
  72.          A_FDBEQ,A_FDBNE,A_FDBGT,A_FDBNGT,A_FDBGE,A_FDBNGE,
  73.          A_FDBLT,A_FDBNLT,A_FDBLE,A_FDBGL,A_FDBNGL,A_FDBGLE,A_FBDNGLE,
  74.          A_FSEQ,A_FSNE,A_FSGT,A_FSNGT,A_FSGE,A_FSNGE,
  75.          A_FSLT,A_FSNLT,A_FSLE,A_FSGL,A_FSNGL,A_FSGLE,A_FSNGLE,
  76.          A_FCMP,A_FDIV,A_FMOVE,A_FMOVEM,
  77.          A_FMUL,A_FNEG,A_FNOP,A_FSQRT,A_FSUB,A_FSGLDIV,
  78.          A_FSFLMUL,A_FTST,
  79.          A_FTRAPEQ,A_FTRAPNE,A_FTRAPGT,A_FTRAPNGT,A_FTRAPGE,A_FTRAPNGE,
  80.          A_FTRAPLT,A_FTRAPNLT,A_FTRAPLE,A_FTRAPGL,A_FTRAPNGL,A_FTRAPGLE,A_FTRAPNGLE,
  81.          { Protected instructions }
  82.          A_CPRESTORE,A_CPSAVE,
  83.          { FPU Unit protected instructions                    }
  84.          { and 68030/68851 common MMU instructions            }
  85.          { (this may include 68040 MMU instructions)          }
  86.          A_FRESTORE,A_FSAVE,A_PFLUSH,A_PFLUSHA,A_PLOAD,A_PMOVE,A_PTEST,
  87.          { Useful for assembly langage output }
  88.          A_LABEL,A_NONE);
  89.  
  90.        { enumeration for registers, don't change the }
  91.        { order of this table                         }
  92.        { Registers which can and will be used by the compiler }
  93.        tregister = (
  94.          R_NO,R_D0,R_D1,R_D2,R_D3,R_D4,R_D5,R_D6,R_D7,
  95.          R_A0,R_A1,R_A2,R_A3,R_A4,R_A5,R_A6,R_SP,
  96.          { PUSH/PULL- quick and dirty hack }
  97.          R_SPPUSH,R_SPPULL,
  98.          { misc. }
  99.          R_CCR,R_FP0,R_FP1,R_FP2,R_FP3,R_FP4,R_FP5,R_FP6,
  100.          R_FP7,R_FPCR,R_SR,R_SSP,R_DFC,R_SFC,R_VBR,R_FPSR,
  101.          { other - not used in reg2str }
  102.          R_DEFAULT_SEG);
  103.  
  104.        { S_NO = No Size of operand }
  105.        { S_B  = Byte size operand  }
  106.        { S_W  = Word size operand  }
  107.        { S_L  = DWord size operand }
  108.        { USED FOR conversions in x86}
  109.        { S_BW = Byte to word       }
  110.        { S_BL = Byte to long       }
  111.        { S_WL = Word to long       }
  112.        { Floating point types      }
  113.        { S_X  = Extended type      }
  114.        { S_Q  = double/64bit integer }
  115.        { S_S  = single type (32 bit) }
  116.        topsize = (S_NO,S_B,S_W,S_L,S_BW,S_BL,S_WL,S_Q,S_S,S_X);
  117.  
  118.        plocation = ^tlocation;
  119.  
  120.        { information about the location of an operand }
  121.        { LOC_FPU         FPU registers = Dn if emulation }
  122.        { LOC_REGISTER    in a processor register }
  123.        { LOC_MEM         in the memory }
  124.        { LOC_REFERENCE   like LOC_MEM, but lvalue }
  125.        { LOC_JUMP        nur bool'sche Resultate, Sprung zu false- oder }
  126.        {                 truelabel }
  127.        { LOC_FLAGS       nur bool'sche Rsultate, Flags sind gesetzt }
  128.        { LOC_CREGISTER   register which shouldn't be modified }
  129.        { LOC_INVALID     added for tracking problems}
  130.  
  131.        tloc = (LOC_INVALID,LOC_FPU,LOC_REGISTER,LOC_MEM,LOC_REFERENCE,LOC_JUMP,
  132.            LOC_FLAGS,LOC_CREGISTER);
  133.  
  134.        tregisterlist = set of tregister;
  135.  
  136.  { F_E = Equal
  137.    F_NE = Not Equal
  138.    F_G = Greater then
  139.    F_L = Less then
  140.    F_GE = Greater or equal then
  141.    F_LE = Less or equal then
  142.    F_C = Carry
  143.    F_NC = Not Carry
  144.    F_A = Above
  145.    F_AE = Above or Equal
  146.    F_B = Below
  147.    F_BE = Below or Equal
  148.    other flags:
  149.    FL_xxx = floating type flags .
  150.  
  151.  }
  152.        tresflags = (F_E,F_NE,F_G,F_L,F_GE,F_LE,F_C,F_NC,
  153.           F_A,F_AE,F_B,F_BE);
  154.           { floating type flags used by FBCC are auotmatically converted }
  155.           { to standard condition codes                                  }
  156. {          FL_E,FL_NE,FL_A,FL_AE,FL_B,FL_BE);}
  157.  
  158.        preference = ^treference;
  159.  
  160.       { direction of address register : }
  161.       {              (An)     (An)+   -(An)  }
  162.       tdirection = (dir_none,dir_inc,dir_dec);
  163.  
  164.        treference = record
  165.       base,segment,index : tregister;
  166.       offset : longint;
  167.       symbol : pstring;
  168.       { indexed increment and decrement mode }
  169.       { (An)+ and -(An)                      }
  170.       direction : tdirection;
  171.       { a constant is also a treference, this makes the code generator }
  172.       { easier                                                         }
  173.       isintvalue : boolean;
  174.       scalefactor : byte;
  175.        end;
  176.  
  177.        tlocation = record
  178.       case loc : tloc of
  179.          { segment in reference at the same place as in loc_register }
  180.          LOC_REGISTER,LOC_CREGISTER : (register,segment : tregister);
  181.          LOC_MEM,LOC_REFERENCE : (reference : treference);
  182.          LOC_FPU : (fpureg:tregister);
  183.          LOC_JUMP : ();
  184.          LOC_FLAGS : (resflags : tresflags);
  185.          LOC_INVALID : ();
  186.        end;
  187.  
  188.        pcsymbol = ^tcsymbol;
  189.  
  190.        tcsymbol = record
  191.       symbol : pchar;
  192.          offset : longint;
  193.        end;
  194.  
  195.     const
  196.  {----------------------------------------------------------------------}
  197.  { F_E = Equal                                                          }
  198.  { F_NE = Not Equal                                                     }
  199.  { F_G = Greater then                                                   }
  200.  { F_L = Less then                                                      }
  201.  { F_GE = Greater or equal then                                         }
  202.  { F_LE = Less or equal then                                            }
  203.  { F_C = Carry                            = C                           }
  204.  { F_NC = Not Carry                       = not C                       }
  205.  { F_A = Above                            = not C and not Z             }
  206.  { F_AE = Above or Equal                  = not C                       }
  207.  { F_B = Below                            = C                           }
  208.  { F_BE = Below or Equal                  = C or Z                      }
  209.  { FL_E = Floating point equal            = Z                           }
  210.  { FL_NE = Floating point Not equal       = not Z                       }
  211.  { FL_A  = Floating point above           =                             }
  212.  { FL_AE = Floating point above or equal  =                             }
  213.  { FL_B  = Floating point below           =                             }
  214.  { FL_BE = Floating point below or equal  =                             }
  215.  
  216.  { THE ORDER OF THIS TABLE SHOULD NOT BE CHANGED! }
  217.  flag_2_jmp: array[F_E..F_BE] of tasmop =
  218.  (A_BEQ,A_BNE,A_BGT,A_BLT,A_BGE,A_BLE,A_BCS,A_BCC,
  219.   A_BHI,A_BCC,A_BCS,A_BLS);
  220.   { floating point jumps - CURRENTLY NOT USED }
  221. {  A_FBEQ,A_FBNE,A_FBGT,A_FBGE,A_FBLT,A_FBLE); }
  222.  
  223.  { don't change the order of this table, it is related to }
  224.  { the flags table.                                       }
  225.  
  226.  flag_2_set: array[F_E..F_BE] of tasmop =
  227.  (A_SEQ,A_SNE,A_SGT,A_SLT,A_SGE,A_SLE,A_SCS,A_SCC,
  228.   A_SHI,A_SCC,A_SCS,A_SLS);
  229.  
  230.  
  231.        { operand types }
  232.        top_none = 0;
  233.        top_reg = 1;
  234.        top_ref = 2;
  235.        top_reglist = 5;
  236.  
  237.        { a constant can be also written as treference }
  238.        top_const = 3;
  239.  
  240.        { this is for calls }
  241.        top_symbol = 4;
  242.  
  243.        {This constant is an alias for the stack pointer, as it's name may
  244.         differ from processor to processor.}
  245.        stack_pointer = R_SP;
  246.  
  247.        frame_pointer = R_A6;
  248.  
  249.        {This constant is an alias for the accumulator, as it's name may
  250.         differ from processor to processor.}
  251.        accumulator = R_D0;
  252.  
  253.     type
  254.  
  255.        pai_extended = ^tai_extended;
  256.  
  257.        { generates an extended - processor specific }
  258.        tai_extended = object(tai)
  259.           value : bestreal;
  260.           constructor init(_value : bestreal);
  261.        end;
  262.  
  263.        pai_comp = ^tai_comp;
  264.  
  265.        { generates a comp - processor specific  }
  266.        tai_comp = object(tai)
  267.           value : bestreal;
  268.           constructor init(_value : bestreal);
  269.        end;
  270.  
  271.        pai_labeled = ^tai_labeled;
  272.  
  273.        tai_labeled = object(tai)
  274.           _operator : tasmop;
  275.           _op1: tregister;
  276.           lab : plabel;
  277.           constructor init(op : tasmop; l : plabel);
  278.           constructor init_reg(op: tasmop; l : plabel; reg: tregister);
  279.           destructor done;virtual;
  280.        end;
  281.  
  282.        pai68k = ^tai68k;
  283.  
  284.        tai68k = object(tai)
  285.       { this isn't a proper style, but not very memory expensive }
  286.       op1,op2,op3 : pointer;
  287.       _operator : tasmop;
  288.       op1t,op2t,op3t : byte;
  289.       size : topsize;
  290.      reglist: set of tregister;
  291.       constructor op_none(op : tasmop;_size : topsize);
  292.  
  293.       constructor op_reg(op : tasmop;_size : topsize;_op1 : tregister);
  294.       constructor op_const(op : tasmop;_size : topsize;_op1 : longint);
  295.       constructor op_ref(op : tasmop;_size : topsize;_op1 : preference);
  296.       constructor op_loc(op : tasmop;_size : topsize;_op1 : tlocation);
  297.  
  298.       constructor op_reg_reg(op : tasmop;_size : topsize;_op1,_op2 : tregister);
  299.       constructor op_reg_ref(op : tasmop;_size : topsize;_op1 : tregister;_op2 : preference);
  300.       constructor op_reg_loc(op : tasmop;_size : topsize;_op1 : tregister;_op2 : tlocation);
  301.       constructor op_loc_reg(op : tasmop;_size : topsize;_op1 : tlocation;_op2 : tregister);
  302.  
  303.       constructor op_const_reg(op : tasmop;_size : topsize;_op1 : longint;_op2 : tregister);
  304.       { this combination is needed by ENTER }
  305.       constructor op_const_const(op : tasmop;_size : topsize;_op1,_op2 : longint);
  306.       constructor op_const_ref(op : tasmop;_size : topsize;_op1 : longint;_op2 : preference);
  307.       constructor op_const_loc(op : tasmop;_size : topsize;_op1 : longint;_op2 : tlocation);
  308.  
  309.       constructor op_ref_reg(op : tasmop;_size : topsize;_op1 : preference;_op2 : tregister);
  310.       { this is only allowed if _op1 is an int value (_op1^.isintvalue=true) }
  311.       constructor op_ref_ref(op : tasmop;_size : topsize;_op1,_op2 : preference);
  312.       {
  313.       constructor op_ref_loc(op : tasmop;_size : topsize;_op1 : preference;_op2 : tlcation);}
  314.  
  315.       constructor op_const_reg_reg(op : tasmop;_size : topsize;_op1 : longint;_op2 : tregister;_op3 : tregister);
  316.  
  317.       { used by MC68020 mul/div }
  318.       constructor op_reg_reg_Reg(op: tasmop;_size: topsize;_op1: tregister; _op2: tregister; _op3: tregister);
  319.  
  320.      { used by link }
  321.      constructor op_reg_const(op: tasmop; _size: topsize; _op1: tregister; _op2: longint);
  322.       { this is for CALL etc.                            }
  323.       { symbol is replaced by the address of symbol      }
  324.       { so op_csymbol(A_PUSH,S_L,strnew('P')); generates }
  325.       { an instruction which pushes the address of P     }
  326.       { to the stack                                     }
  327.       constructor op_csymbol(op : tasmop;_size : topsize;_op1 : pcsymbol);
  328.       constructor op_csymbol_reg(op : tasmop;_size : topsize;_op1 : pcsymbol;_op2 : tregister);
  329.       constructor op_csymbol_ref(op : tasmop;_size : topsize;_op1 : pcsymbol;_op2 : preference);
  330.       constructor op_csymbol_loc(op : tasmop;_size : topsize;_op1 : pcsymbol;_op2 : tlocation);
  331.  
  332.      constructor op_ref_reglist(op: tasmop; _size : topsize; _op1: preference;_op2: tregisterlist);
  333.      constructor op_reglist_ref(op: tasmop; _size : topsize; _op1: tregisterlist; _op2: preference);
  334.  
  335.       destructor done;virtual;
  336.        end;
  337.  
  338. const
  339.        ait_bestreal = ait_real_64bit;
  340. type
  341.        pai_bestreal = pai_double;
  342.        tai_bestreal = tai_double;
  343.  
  344.     const
  345.        maxvarregs = 5;
  346.  
  347.        varregs : array[1..maxvarregs] of tregister =
  348.      (R_D2,R_D3,R_D4,R_D5,R_D7);
  349.  
  350.        nextlabelnr : longint = 1;
  351.  
  352.  
  353.     { resets all values of ref to defaults }
  354.     procedure reset_reference(var ref : treference);
  355.  
  356.     { same as reset_reference, but symbol is disposed }
  357.     { use this only for already used references       }
  358.     procedure clear_reference(var ref : treference);
  359.  
  360.     { make l as a new label }
  361.     procedure getlabel(var l : plabel);
  362.     { frees the label if unused }
  363.     procedure freelabel(var l : plabel);
  364.     { make a new zero label }
  365.     procedure getzerolabel(var l : plabel);
  366.     { reset a label to a zero label }
  367.     procedure setzerolabel(var l : plabel);
  368.     {just get a label number }
  369.     procedure getlabelnr(var l : longint);
  370.  
  371.     function newreference(const r : treference) : preference;
  372.  
  373.     function reg2str(r : tregister) : string;
  374.  
  375.     { generates an help record for constants }
  376.     function newcsymbol(const s : string;l : longint) : pcsymbol;
  377.  
  378.     function lab2str(l : plabel) : string;
  379.  
  380.     const
  381.        ao_unknown = $0;
  382.        { 8 bit reg }
  383.        ao_reg8 = $1;
  384.        { 16 bit reg }
  385.        ao_reg16 = $2;
  386.        { 32 bit reg }
  387.        ao_reg32 = $4;
  388.        ao_reg = (ao_reg8 or ao_reg16 or ao_reg32);
  389.  
  390.  
  391.        { for  push/pop operands }
  392.        ao_wordreg = (ao_reg16 or ao_reg32);
  393.        ao_imm8 = $8;            { 8 bit immediate }
  394.        ao_imm8S   = $10;                { 8 bit immediate sign extended }
  395.        ao_imm16   = $20;                { 16 bit immediate }
  396.        ao_imm32   = $40;                { 32 bit immediate }
  397.        ao_imm1    = $80;        { 1 bit immediate }
  398.  
  399.        { for  unknown expressions }
  400.        ao_immunknown = ao_imm32;
  401.  
  402.        { gen'l immediate }
  403.        ao_imm = (ao_imm8 or ao_imm8S or ao_imm16 or ao_imm32);
  404.        ao_disp8   = $200;               { 8 bit displacement (for  jumps) }
  405.        ao_disp16  = $400;               { 16 bit displacement }
  406.        ao_disp32  = $800;               { 32 bit displacement }
  407.  
  408.        { general displacement }
  409.        ao_disp    = (ao_disp8 or ao_disp16 or ao_disp32);
  410.  
  411.        { for  unknown size displacements }
  412.        ao_dispunknown = ao_disp32;
  413.        ao_mem8    = $1000;
  414.        ao_mem16   = $2000;
  415.        ao_mem32   = $4000;
  416.        ao_baseindex = $8000;
  417.  
  418.        { general mem }
  419.        ao_mem     = (ao_disp or ao_mem8 or ao_mem16 or ao_mem32 or ao_baseindex);
  420.        ao_wordmem = (ao_mem16 or ao_mem32 or ao_disp or ao_baseindex);
  421.        ao_bytemem = (ao_mem8 or ao_disp or ao_baseindex);
  422.  
  423.        ao_control = $40000;     { Control register }
  424.        ao_debug   = $80000;     { Debug register }
  425.        ao_test    = $100000;    { Test register }
  426.        ao_floatreg = $200000;   { Float register }
  427.  
  428.  
  429.        ao_jumpabsolute = $4000000;
  430.        ao_abs8 = $08000000;
  431.        ao_abs16 = $10000000;
  432.        ao_abs32 = $20000000;
  433.        ao_abs = (ao_abs8 or ao_abs16 or ao_abs32);
  434.  
  435.        ao_none = $ff;
  436.  
  437.   const
  438.      AB_DN     =  1;
  439.      AB_AN     =  2;
  440.      AB_INDAN  =  3;
  441.      AB_INDPP  =  4;
  442.      AB_MMIND  =  5;
  443.      AB_OFFAN  =  6;
  444.      AB_OFFIDX =  7;
  445.      AB_ABSW   =  8;
  446.      AB_ABSL   =  9;
  447.      AB_OFFPC  =  10;
  448.      AB_OFFIDXPC =11;
  449.      AB_IMM      =12;
  450.      AB_REGS     =13;       {*  movem       *}
  451.      AB_BBRANCH  =14;
  452.      AB_WBRANCH  =15;
  453.      AB_CCR      =16;
  454.      AB_SR       =17;
  455.      AB_USP      =18;
  456.      AB_MULDREGS =19;
  457.      AB_MULDREGU =20;
  458.  
  459.      AF_DN      =(1 SHL AB_DN);
  460.      AF_AN      =(1 SHL AB_AN);
  461.      AF_INDAN   = (1 SHL AB_INDAN);
  462.      AF_INDPP   = (1 SHL AB_INDPP);
  463.      AF_MMIND   = (1 SHL AB_MMIND);
  464.      AF_OFFAN   = (1 SHL AB_OFFAN);
  465.      AF_OFFIDX  = (1 SHL AB_OFFIDX);
  466.      AF_ABSW    = (1 SHL AB_ABSW);
  467.      AF_ABSL    = (1 SHL AB_ABSL);
  468.      AF_OFFPC   = (1 SHL AB_OFFPC);
  469.      AF_OFFIDXPC= (1 SHL AB_OFFIDXPC);
  470.      AF_IMM      =(1 SHL AB_IMM);
  471.      AF_REGS    = (1 SHL AB_REGS);
  472.      AF_BBRANCH = (1 SHL AB_BBRANCH);
  473.      AF_WBRANCH = (1 SHL AB_WBRANCH);
  474.      AF_CCR     =(1 SHL AB_CCR);
  475.      AF_SR      =(1 SHL AB_SR);
  476.      AF_USP     =(1 SHL AB_USP);
  477.      AF_MULDREGS= (1 SHL AB_MULDREGS);
  478.      AF_MULDREGU= (1 SHL AB_MULDREGU);
  479.  
  480.       AF_ALL     = AF_DN OR AF_AN OR AF_INDAN OR AF_INDPP OR AF_MMIND OR AF_OFFAN OR AF_OFFIDX OR AF_ABSW OR
  481.                   AF_ABSL OR AF_OFFPC OR AF_OFFIDXPC OR AF_IMM;
  482.       AF_ALLNA  = AF_DN OR AF_INDAN OR AF_INDPP OR AF_MMIND OR AF_OFFAN OR AF_OFFIDX OR AF_ABSW OR AF_ABSL
  483.                   OR AF_OFFPC OR AF_OFFIDXPC OR AF_IMM;
  484.  
  485.       AF_ALT      = AF_DN OR AF_AN OR AF_INDAN OR AF_INDPP OR AF_MMIND OR AF_OFFAN OR
  486.                    AF_OFFIDX OR AF_ABSW OR AF_ABSL;
  487.  
  488.       AF_ALTNA    = AF_DN OR AF_INDAN OR AF_INDPP OR AF_MMIND OR AF_OFFAN OR AF_OFFIDX OR AF_ABSW OR AF_ABSL;
  489.       AF_ALTM     = AF_INDAN OR AF_INDPP OR AF_MMIND OR AF_OFFAN OR AF_OFFIDX OR AF_ABSW OR AF_ABSL;
  490.       AF_CTL       = AF_INDAN OR AF_OFFAN OR AF_OFFIDX OR AF_ABSW OR AF_ABSL OR AF_OFFPC OR AF_OFFIDXPC;
  491.       AF_CTLNPC   = AF_INDAN OR AF_OFFAN OR AF_OFFIDX OR AF_ABSW OR AF_ABSL OR AF_OFFIDXPC;
  492.  
  493.  
  494. { S_WL  (S_W|S_L)
  495.  S_BW   (S_B|S_W)}
  496.      const
  497.        S_ALL = [S_B] + [S_W] + [S_L];
  498. {#define S_ALL  (S_B|S_W|S_L)}
  499.  
  500.  
  501.     type
  502.      ttemplate = record
  503.         i : tasmop;
  504.         oc : longint;
  505.         ops : byte;
  506.        size: set of topsize;
  507.         o1,o2: longint;
  508.     end;
  509.  
  510.        tins_cache = array[A_ABCD..A_UNLK] of longint;
  511.  
  512.     var
  513.        ins_cache : tins_cache;
  514.        exprasmlist : paasmoutput;
  515.  
  516.     const
  517.        it : array[0..188] of ttemplate = (
  518.  
  519.     (   i:A_ABCD; oc: $C100; ops:2;size: [S_B];  o1:AF_DN;      o2:AF_DN           ),
  520.     (   i:A_ABCD; oc: $C108; ops:2;size: [S_B];  o1:AF_MMIND;   o2:AF_MMIND        ),
  521.     (   i:A_ADD;  oc: $D000; ops:2;size: S_ALL;  o1:AF_ALL;     o2:AF_DN           ),
  522.     (   i:A_ADD;  oc: $D100; ops:2;size: S_ALL;  o1:AF_DN;      o2:AF_ALTM         ),
  523.     (   i:A_ADD;  oc: $D0C0; ops:2;size: [S_W];  o1:AF_ALL;     o2:AF_AN           ),
  524.     (   i:A_ADD;  oc: $D1C0; ops:2;size: [S_L];  o1:AF_ALL;     o2:AF_AN           ),
  525.     (   i:A_ADD;  oc: $0600; ops:2;size: S_ALL;  o1:AF_IMM;     o2:AF_ALTNA        ),
  526.     (   i:A_ADDQ; oc: $5000; ops:2;size: S_ALL;  o1:AF_IMM;     o2:AF_ALT        ),
  527.     (   i:A_ADDX; oc: $D100; ops:2;size: S_ALL;  o1:AF_DN;      o2:AF_DN           ),
  528.     (   i:A_ADDX; oc: $D108; ops:2;size: S_ALL;  o1:AF_MMIND;   o2:AF_MMIND        ),
  529.     (   i:A_AND;  oc: $C000; ops:2;size: S_ALL;  o1:AF_ALLNA;   o2:AF_DN           ),
  530.     (   i:A_AND;  oc: $C100; ops:2;size: S_ALL;  o1:AF_DN;      o2:AF_ALTM         ),
  531.     (   i:A_AND;  oc: $0200; ops:2;size: S_ALL;  o1:AF_IMM;     o2:AF_ALTNA        ),
  532.     (   i:A_AND;  oc: $023C; ops:2;size: [S_B];  o1:AF_IMM;     o2:AF_CCR          ),
  533.     (   i:A_AND;  oc: $027C; ops:2;size: [S_W];  o1:AF_IMM;     o2:AF_SR           ),
  534.     (   i:A_ASL;  oc: $E120; ops:2;size: S_ALL;  o1:AF_DN;      o2:AF_DN           ),
  535.     (   i:A_ASL;  oc: $E100; ops:2;size: S_ALL;  o1:AF_IMM;     o2:AF_DN         ),
  536.     (   i:A_ASL;  oc: $E1C0; ops:1;size: [S_W];  o1:0;          o2:AF_ALTM         ),
  537.     (   i:A_ASR;  oc: $E020; ops:2;size: S_ALL;  o1:AF_DN;      o2:AF_DN           ),
  538.     (   i:A_ASR;  oc: $E000; ops:2;size: S_ALL;  o1:AF_IMM;     o2:AF_DN           ),
  539.     (   i:A_ASR;  oc: $E0C0; ops:1;size: [S_W];  o1:0;          o2:AF_ALTM         ),
  540.  
  541.     (   i:A_BCC;  oc: $6400; ops:1;size: [S_NO]; o1:AF_WBRANCH; o2:0               ),
  542.     (   i:A_BCS;  oc: $6500; ops:1;size: [S_NO]; o1:AF_WBRANCH; o2:0             ),
  543.     (   i:A_BEQ;  oc: $6700; ops:1;size: [S_NO]; o1:AF_WBRANCH; o2:0             ),
  544.     (   i:A_BGE;  oc: $6C00; ops:1;size: [S_NO]; o1:AF_WBRANCH; o2:0             ),
  545.     (   i:A_BGT;  oc: $6E00; ops:1;size: [S_NO]; o1:AF_WBRANCH; o2:0             ),
  546.     (   i:A_BHI;  oc: $6200; ops:1;size: [S_NO]; o1:AF_WBRANCH; o2:0             ),
  547.     (   i:A_BLE;  oc: $6F00; ops:1;size: [S_NO]; o1:AF_WBRANCH; o2:0               ),
  548.     (   i:A_BLS;  oc: $6300; ops:1;size: [S_NO]; o1:AF_WBRANCH; o2:0               ),
  549.     (   i:A_BLT;  oc: $6D00; ops:1;size: [S_NO]; o1:AF_WBRANCH; o2:0               ),
  550.     (   i:A_BMI;  oc: $6B00; ops:1;size: [S_NO]; o1:AF_WBRANCH; o2:0             ),
  551.     (   i:A_BNE;  oc: $6600; ops:1;size: [S_NO]; o1:AF_WBRANCH; o2:0             ),
  552.     (   i:A_BPL;  oc: $6A00; ops:1;size: [S_NO]; o1:AF_WBRANCH; o2:0             ),
  553.     (   i:A_BVC;  oc: $6800; ops:1;size: [S_NO]; o1:AF_WBRANCH; o2:0             ),
  554.     (   i:A_BVS;  oc: $6900; ops:1;size: [S_NO]; o1:AF_WBRANCH; o2:0             ),
  555.  
  556.     {*      opcode   Temp   Rs  EAs Rd  EAd Siz Sizes  SModes   DModes    Spec# *}
  557.  
  558.     (   i:A_BCHG; oc: $0140;  ops:2;size: [S_B];    o1:AF_DN;      o2:AF_ALTM         ),
  559.     (   i:A_BCHG; oc: $0140;  ops:2;size: [S_L];    o1:AF_DN;      o2:AF_DN           ),
  560.     (   i:A_BCHG; oc: $0840;  ops:2;size: [S_B];    o1:AF_IMM;     o2:AF_ALTM         ),
  561.     (   i:A_BCHG; oc: $0840;  ops:2;size: [S_L];    o1:AF_IMM;     o2:AF_DN           ),
  562.     (   i:A_BCLR; oc: $0180;  ops:2;size: [S_B];    o1:AF_DN;      o2:AF_ALTM         ),
  563.     (   i:A_BCLR; oc: $0180;  ops:2;size: [S_L];    o1:AF_DN;      o2:AF_DN           ),
  564.     (   i:A_BCLR; oc: $0880;  ops:2;size: [S_B];    o1:AF_IMM;     o2:AF_ALTM         ),
  565.     (   i:A_BCLR; oc: $0880;  ops:2;size: [S_L];    o1:AF_IMM;     o2:AF_DN           ),
  566.  
  567.     (   i:A_BRA;  oc: $6000;  ops:1;size: [S_NO];    o1:AF_WBRANCH;o2:0              ),
  568.  
  569.     (   i:A_BSET; oc: $01C0;  ops:2;size: [S_B];    o1:AF_DN;      o2:AF_ALTM         ),
  570.     (   i:A_BSET; oc: $01C0;  ops:2;size: [S_L];    o1:AF_DN;      o2:AF_DN           ),
  571.     (   i:A_BSET; oc: $08C0;  ops:2;size: [S_B];    o1:AF_IMM;     o2:AF_ALTM         ),
  572.     (   i:A_BSET; oc: $08C0;  ops:2;size: [S_L];    o1:AF_IMM;     o2:AF_DN           ),
  573.     (   i:A_BTST; oc: $0100;  ops:2;size: [S_B];    o1:AF_DN;      o2:AF_ALTM         ),
  574.     (   i:A_BTST; oc: $0100;  ops:2;size: [S_L];    o1:AF_DN;      o2:AF_DN           ),
  575.     (   i:A_BTST; oc: $0800;  ops:2;size: [S_B];    o1:AF_IMM;     o2:AF_ALTM         ),
  576.     (   i:A_BTST; oc: $0800;  ops:2;size: [S_L];    o1:AF_IMM;     o2:AF_DN           ),
  577.  
  578.     {*      opcode   Temp   Rs  EAs Rd  EAd Siz Sizes  SModes   DModes    Spec# *}
  579.  
  580.     (   i:A_CHK;  oc: $4180;  ops:2;size: [S_W];  o1:AF_ALLNA;   o2:AF_DN           ),
  581.     (   i:A_CLR;  oc: $4200;  ops:1;size: S_ALL;  o1:AF_ALTNA;   o2:0  ),
  582.     (   i:A_CMP;  oc: $B000;  ops:2;size: S_ALL;  o1:AF_ALLNA;   o2:AF_DN           ),
  583.     (   i:A_CMP;  oc: $B000;  ops:2;size: [S_WL]; o1:AF_AN;      o2:AF_DN           ),
  584.     (   i:A_CMP;  oc: $B0C0;  ops:2;size: [S_W];  o1:AF_ALL;     o2:AF_AN           ),
  585.     (   i:A_CMP;  oc: $B1C0;  ops:2;size: [S_L];  o1:AF_ALL;     o2:AF_AN           ),
  586.     ( i:A_CMP;  oc: $0C00;  ops:2;size: S_ALL;  o1:AF_IMM;     o2:AF_ALTNA        ),
  587.     (   i:A_CMP;  oc: $B108;  ops:2;size: S_ALL;  o1:AF_INDPP;   o2:AF_INDPP        ),
  588.  
  589.     ( i:A_DBCC; oc: $54C8;  ops:2;size: [S_NO];    o1:AF_DN;   o2:AF_WBRANCH       ),
  590.     (   i:A_DBCS; oc: $55C8;  ops:2;size: [S_NO];    o1:AF_DN;   o2:AF_WBRANCH       ),
  591.     (   i:A_DBEQ; oc: $57C8;  ops:2;size: [S_NO];    o1:AF_DN;   o2:AF_WBRANCH       ),
  592.     (   i:A_DBF; oc: $51C8;   ops:2;size: [S_NO];    o1:AF_DN;   o2:AF_WBRANCH       ),
  593.     (   i:A_DBGE; oc: $5CC8;  ops:2;size: [S_NO];    o1:AF_DN;   o2:AF_WBRANCH       ),
  594.     (   i:A_DBGT; oc: $5EC8;  ops:2;size: [S_NO];    o1:AF_DN;   o2:AF_WBRANCH       ),
  595.     (   i:A_DBHI; oc: $52C8;  ops:2;size: [S_NO];    o1:AF_DN;   o2:AF_WBRANCH       ),
  596.     (   i:A_DBLE; oc: $5FC8;  ops:2;size: [S_NO];    o1:AF_DN;   o2:AF_WBRANCH       ),
  597.     (   i:A_DBLS; oc: $53C8;  ops:2;size: [S_NO];    o1:AF_DN;   o2:AF_WBRANCH       ),
  598.     (   i:A_DBLT; oc: $5DC8;  ops:2;size: [S_NO];    o1:AF_DN;   o2:AF_WBRANCH       ),
  599.     (   i:A_DBMI; oc: $5BC8;  ops:2;size: [S_NO];    o1:AF_DN;   o2:AF_WBRANCH       ),
  600.     (   i:A_DBNE; oc: $56C8;  ops:2;size: [S_NO];    o1:AF_DN;   o2:AF_WBRANCH       ),
  601.     (   i:A_DBPL; oc: $5AC8;  ops:2;size: [S_NO];    o1:AF_DN;   o2:AF_WBRANCH       ),
  602.     (   i:A_DBT; oc: $50C8;   ops:2;size: [S_NO];    o1:AF_DN;   o2:AF_WBRANCH       ),
  603.     (   i:A_DBVC; oc: $58C8;  ops:2;size: [S_NO];    o1:AF_DN;   o2:AF_WBRANCH       ),
  604.     (   i:A_DBVS; oc: $59C8;  ops:2;size: [S_NO];    o1:AF_DN;   o2:AF_WBRANCH       ),
  605.  
  606.     {*      opcode   Temp   Rs  EAs Rd  EAd Siz Sizes  SModes   DModes    Spec# *}
  607.  
  608.     (   i:A_DIVS; oc: $81C0;  ops:2;size: [S_W];    o1:AF_ALLNA;   o2:AF_DN           ),
  609.     (   i:A_DIVS; oc: $4C40;  ops:2;size: [S_L];    o1:AF_ALLNA;   o2:AF_DN OR AF_MULDREGS),  {*  020 *}
  610.     (   i:A_DIVU; oc: $80C0;  ops:2;size: [S_W];    o1:AF_ALLNA;   o2:AF_DN           ),
  611.     (   i:A_DIVU; oc: $4C40;  ops:2;size: [S_L];    o1:AF_ALLNA;   o2:AF_DN OR AF_MULDREGU),  {*  020 *}
  612.  
  613.  
  614.     (   i:A_EOR;   oc: $B100; ops:2;size: S_ALL;  o1:AF_DN;      o2:AF_ALTNA        ),
  615.     (   i:A_EOR;  oc: $0A00;  ops:2;size: S_ALL;  o1:AF_IMM;     o2:AF_ALTNA        ),
  616.     (   i:A_EOR;  oc: $0A3C;  ops:2;size: [S_B];  o1:AF_IMM;     o2:AF_CCR          ),
  617.     (   i:A_EOR;  oc: $0A7C;  ops:2;size: [S_W];  o1:AF_IMM;     o2:AF_SR           ),
  618.     (   i:A_EXG;  oc: $C140;  ops:2;size: [S_L];  o1:AF_DN;      o2:AF_DN           ),
  619.     (   i:A_EXG;  oc: $C148;  ops:2;size: [S_L];  o1:AF_AN;      o2:AF_AN           ),
  620.     (   i:A_EXG;  oc: $C188;  ops:2;size: [S_L];  o1:AF_DN;      o2:AF_AN           ),
  621.     (   i:A_EXG;  oc: $C188;  ops:2;size: [S_L];  o1:AF_AN;      o2:AF_DN           ),
  622.     (   i:A_EXT;  oc: $4880;  ops:1;size: [S_W];  o1:AF_DN;      o2:0    ),
  623.     (   i:A_EXT;  oc: $48C0;  ops:1;size: [S_L];  o1:AF_DN;      o2:0    ),
  624.     { MC68020 }
  625.     (   i:A_EXTB; oc: $49C0;  ops:1;size: [S_L];  o1:AF_DN;      o2:0    ),
  626.     (   i:A_ILLEGAL;oc: $4AFC;ops:0;size: [S_NO];   o1:0;             o2:0    ),
  627.  
  628.  
  629.     {*
  630.      *  note: BSR/BSR/JSR ordering must remain as it is (passc.c optimizations)
  631.      *}
  632.     (   i:A_JMP;  oc: $4EC0;  ops:1;size: [S_NO];      o1:AF_CTL;     o2:0               ),
  633.     (   i:A_BSR;  oc: $6100;  ops:1;size: [S_NO];      o1:AF_WBRANCH; o2: 0              ),
  634.     (   i:A_JSR;  oc: $4E80;  ops:1;size: [S_NO];      o1:AF_CTL;     o2:0               ),
  635.  
  636.     (   i:A_LEA;  oc: $41C0;  ops:2;size: [S_L];    o1:AF_CTL;     o2:AF_AN           ),
  637.     (   i:A_LINK; oc: $4E50;  ops:2;size: [S_W];    o1:AF_AN;      o2:AF_IMM          ),
  638.  
  639.     {*      opcode   Temp   Rs  EAs Rd  EAd Siz Sizes  SModes   DModes    Spec# *}
  640.  
  641.     (   i:A_LSL;  oc: $E128;  ops:2;size: S_ALL;  o1:AF_DN;      o2:AF_DN           ),
  642.     (   i:A_LSL;  oc: $E108;  ops:2;size: S_ALL;  o1:AF_IMM;     o2:AF_DN           ),
  643.     (   i:A_LSL;  oc: $E3C0;  ops:1;size: [S_W];  o1:0;          o2:AF_ALTM         ),
  644.     (   i:A_LSR;  oc: $E028;  ops:2;size: S_ALL;  o1:AF_DN;      o2:AF_DN           ),
  645.     (   i:A_LSR;  oc: $E008;  ops:2;size: S_ALL;  o1:AF_IMM;     o2:AF_DN           ),
  646.     (   i:A_LSR;  oc: $E2C0;  ops:1;size: [S_W];  o1:0;          o2:AF_ALTM         ),
  647.  
  648.     (   i:A_MOVE; oc: $2000;  ops:2;size: [S_L];    o1:AF_ALLNA;   o2:AF_ALTNA        ),
  649.     (   i:A_MOVE; oc: $3000;  ops:2;size: [S_W];    o1:AF_ALLNA;   o2:AF_ALTNA        ),
  650.     (   i:A_MOVE; oc: $1000;  ops:2;size: [S_B];    o1:AF_ALLNA;   o2:AF_ALTNA        ),
  651.     (   i:A_MOVE; oc: $2000;  ops:2;size: [S_L];    o1:AF_AN;      o2:AF_ALTNA        ),
  652.     (   i:A_MOVE; oc: $3000;  ops:2;size: [S_W];    o1:AF_AN;      o2:AF_ALTNA        ),
  653.  
  654.   {* 68010
  655.    *(   'MOVE'; i:A_MOVE; oc: $42C0; -1; -1;  0;  3; -1; size: [S_W];    o1:AF_CCR;     o1:AF_ALTNA        ),
  656.    *}
  657.  
  658.     (   i:A_MOVE; oc: $44C0;  ops:2;size: [S_W];    o1:AF_ALLNA;   o2:AF_CCR          ),
  659.     (   i:A_MOVE; oc: $46C0;  ops:2;size: [S_W];    o1:AF_ALLNA;   o2:AF_SR           ),
  660.     (   i:A_MOVE; oc: $40C0;  ops:2;size: [S_W];    o1:AF_SR;      o2:AF_ALTNA        ),
  661.     (   i:A_MOVE; oc: $3040;  ops:2;size: [S_W];    o1:AF_ALL;     o2:AF_AN           ),
  662.     (   i:A_MOVE; oc: $2040;  ops:2;size: [S_L];    o1:AF_ALL;     o2:AF_AN           ),
  663.     (   i:A_MOVE; oc: $4E68;  ops:2;size: [S_L];    o1:AF_USP;     o2:AF_AN           ),
  664.     (   i:A_MOVE; oc: $4E60;  ops:2;size: [S_L];    o1:AF_AN;      o2:AF_USP          ),
  665.     {* MOVEC 68010  *}
  666.     (   i:A_MOVEM;oc: $48C0; ops:8;size: [S_L];    o1:AF_REGS;    o2:AF_CTL OR AF_MMIND ),
  667.     (   i:A_MOVEM;oc: $4880; ops:8;size: [S_W];    o1:AF_REGS;    o2:AF_CTL OR AF_MMIND ),
  668.     (   i:A_MOVEM;oc: $4CC0; ops:8;size: [S_L];    o1:AF_CTL OR AF_INDPP;    o2:AF_REGS ),
  669.     (   i:A_MOVEM;oc: $4C80; ops:8;size: [S_W];    o1:AF_CTL OR AF_INDPP;    o2:AF_REGS ),
  670.     (   i:A_MOVEP;oc: $0188; ops:2;size: [S_W];    o1:AF_DN;      o2:AF_OFFAN        ),
  671.     (   i:A_MOVEP;oc: $01C8; ops:2;size: [S_L];    o1:AF_DN;      o2:AF_OFFAN        ),
  672.     (   i:A_MOVEP;oc: $0108; ops:2;size: [S_W];    o1:AF_OFFAN;   o2:AF_DN           ),
  673.     (   i:A_MOVEP;oc: $0148; ops:2;size: [S_L];    o1:AF_OFFAN;   o2:AF_DN           ),
  674.     {*  MOVES   68010   *}
  675.     (   i:A_MOVEQ;oc: $7000; ops:2;size: [S_L];    o1:AF_IMM;    o2:AF_DN           ),
  676.  
  677.     {*      opcode   Temp   Rs  EAs Rd  EAd Siz Sizes  SModes   DModes    Spec# *}
  678.  
  679.     (   i:A_MULS; oc: $C1C0;  ops:2;size: [S_W];    o1:AF_ALLNA;   o2:AF_DN           ),
  680.     (   i:A_MULS; oc: $4C00;  ops:2;size: [S_L];    o1:AF_ALLNA;   o2:AF_DN OR AF_MULDREGS),  {*  020 *}
  681.     (   i:A_MULU; oc: $C0C0;  ops:2;size: [S_W];    o1:AF_ALLNA;   o2:AF_DN           ),
  682.     (   i:A_MULU; oc: $4C00;  ops:2;size: [S_L];    o1:AF_ALLNA;   o2:AF_DN OR AF_MULDREGU),  {*  020 *}
  683.     (   i:A_NBCD; oc: $4800;  ops:1;size: [S_B];    o1:AF_ALTNA;   o2:0    ),
  684.     (   i:A_NEG;  oc: $4400;  ops:1;size: S_ALL;    o1:AF_ALTNA;   o2:0    ),
  685.     (   i:A_NEGX; oc: $4000;  ops:1;size: S_ALL;    o1:AF_ALTNA;   o2:0    ),
  686.     (   i:A_NOP;  oc: $4E71;  ops:0;size: [S_NO];   o1:0;          o2:0    ),
  687.     (   i:A_NOT;  oc: $4600;  ops:1;size: S_ALL;    o1:AF_ALTNA;   o2:0    ),
  688.  
  689.     (   i:A_OR;   oc: $8000;  ops:2;size: S_ALL;    o1:AF_ALLNA;   o2:AF_DN           ),
  690.     (   i:A_OR;   oc: $8100;  ops:2;size: S_ALL;    o1:AF_DN;      o2:AF_ALTNA        ),
  691.     ( i:A_OR;   oc: $0000;  ops:2;size: S_ALL;    o1:AF_IMM;     o2:AF_ALTNA        ),
  692.     (   i:A_OR;   oc: $003C;  ops:2;size: [S_B];    o1:AF_IMM;     o2:AF_CCR          ),
  693.     (   i:A_OR;   oc: $007C;  ops:2;size: [S_W];    o1:AF_IMM;     o2:AF_SR           ),
  694.     (   i:A_PEA;  oc: $4840;  ops:1;size: [S_L];    o1:AF_CTL;     o2:0               ),
  695.     (   i:A_RESET;oc: $4E70;  ops:0;size: [S_NO];   o1:0;          o2:0               ),
  696.  
  697.     {*      opcode   Temp   Rs  EAs Rd  EAd Siz Sizes  SModes   DModes    Spec# *}
  698.  
  699.     (   i:A_ROL;  oc: $E138;  ops:2;size: S_ALL;  o1:AF_DN;      o2:AF_DN           ),
  700.     (   i:A_ROL;  oc: $E118;  ops:2;size: S_ALL;  o1:AF_IMM;     o2:AF_DN           ),
  701.     (   i:A_ROL;  oc: $E7C0;  ops:1;size: [S_W];  o1:AF_ALTM;    o2:0               ),
  702.     (   i:A_ROR;  oc: $E038;  ops:2;size: S_ALL;  o1:AF_DN;      o2:AF_DN           ),
  703.     (   i:A_ROR;  oc: $E018;  ops:2;size: S_ALL;  o1:AF_IMM;     o2:AF_DN           ),
  704.     (   i:A_ROR;  oc: $E6C0;  ops:1;size: [S_W];  o1:AF_ALTM;    o2:0               ),
  705.  
  706.     (   i:A_ROXL; oc: $E130;  ops:2;size: S_ALL;  o1:AF_DN;      o2:AF_DN           ),
  707.     (   i:A_ROXL; oc: $E110;  ops:2;size: S_ALL;  o1:AF_IMM;     o2:AF_DN           ),
  708.     (   i:A_ROXL; oc: $E5C0;  ops:1;size: [S_W];  o1:AF_ALTM;    o2:0               ),
  709.     (   i:A_ROXR; oc: $E030;  ops:2;size: S_ALL;  o1:AF_DN;      o2:AF_DN           ),
  710.     (   i:A_ROXR; oc: $E010;  ops:2;size: S_ALL;  o1:AF_IMM;     o2:AF_DN           ),
  711.     (   i:A_ROXR; oc: $E4C0;  ops:1;size: [S_W];  o1:AF_ALTM;    o2:0               ),
  712.  
  713.     {*  RTD 68010   *}
  714.     (   i:A_RTE;  oc: $4E73;  ops:0;size: [S_NO];   o1:0;          o2:0               ),
  715.     (   i:A_RTR;  oc: $4E77;  ops:0;size: [S_NO];   o1:0;          o2:0               ),
  716.     (   i:A_RTS;  oc: $4E75;  ops:0;size: [S_NO];   o1:0;          o2:0               ),
  717.     (   i:A_SBCD; oc: $8100;  ops:2;size: [S_B];    o1:AF_DN;      o2:AF_DN           ),
  718.     (   i:A_SBCD; oc: $8108;  ops:2;size: [S_B];    o1:AF_MMIND;   o2:AF_MMIND        ),
  719.  
  720.     {*      opcode   Temp   Rs  EAs Rd  EAd Siz Sizes  SModes   DModes    Spec# *}
  721.  
  722.     {* SCC note; even though they are in the same group since all have the
  723.      * same note if one isn't accepted none of the others will be either
  724.      *}
  725.  
  726.     (   i:A_SCC;  oc: $54C0;  ops:1;size: [S_B]; o1:AF_ALTNA; o2: 0        ),
  727.     (   i:A_SCS;  oc: $55C0;  ops:1;size: [S_B]; o1:AF_ALTNA; o2: 0        ),
  728.     (   i:A_SEQ;  oc: $57C0;  ops:1;size: [S_B]; o1:AF_ALTNA; o2: 0        ),
  729.     (   i:A_SF;   oc: $51C0;  ops:1;size: [S_B]; o1:AF_ALTNA; o2: 0        ),
  730.     (   i:A_SGE;  oc: $5CC0;  ops:1;size: [S_B]; o1:AF_ALTNA; o2: 0        ),
  731.     (   i:A_SGT;  oc: $5EC0;  ops:1;size: [S_B]; o1:AF_ALTNA; o2: 0        ),
  732.     (   i:A_SHI;  oc: $52C0;  ops:1;size: [S_B]; o1:AF_ALTNA; o2: 0        ),
  733.     (   i:A_SLE;  oc: $5FC0;  ops:1;size: [S_B]; o1:AF_ALTNA; o2: 0        ),
  734.     (   i:A_SLS;  oc: $53C0;  ops:1;size: [S_B]; o1:AF_ALTNA; o2: 0        ),
  735.     (   i:A_SLT;  oc: $5DC0;  ops:1;size: [S_B]; o1:AF_ALTNA; o2: 0        ),
  736.     (   i:A_SMI;  oc: $5BC0;  ops:1;size: [S_B]; o1:AF_ALTNA; o2: 0        ),
  737.     (   i:A_SNE;  oc: $56C0;  ops:1;size: [S_B]; o1:AF_ALTNA; o2: 0        ),
  738.     (   i:A_SPL;  oc: $5AC0;  ops:1;size: [S_B]; o1:AF_ALTNA; o2: 0        ),
  739.     (   i:A_ST;   oc: $50C0;  ops:1;size: [S_B]; o1:AF_ALTNA; o2: 0        ),
  740.     (   i:A_SVC;  oc: $58C0;  ops:1;size: [S_B]; o1:AF_ALTNA; o2: 0        ),
  741.     (   i:A_SVS;  oc: $59C0;  ops:1;size: [S_B]; o1:AF_ALTNA; o2: 0        ),
  742.  
  743.     {*      opcode   Temp   Rs  EAs Rd  EAd Siz Sizes  SModes   DModes    Spec# *}
  744.  
  745.     (   i:A_STOP; oc: $4E72; ops:0; size: [S_W]; o1:AF_IMM;  o2:   0               ),
  746.  
  747.     (   i:A_SUB;  oc: $9000; ops:2;size: S_ALL;  o1:AF_ALL;     o2:AF_DN           ),
  748.     (   i:A_SUB;  oc: $9100; ops:2;size: S_ALL;  o1:AF_DN;      o2:AF_ALTM         ),
  749.     (   i:A_SUB;  oc: $90C0; ops:2;size: [S_W];  o1:AF_ALL;     o2:AF_AN           ),
  750.     (   i:A_SUB;  oc: $91C0; ops:2;size: [S_L];  o1:AF_ALL;     o2:AF_AN           ),
  751.     (   i:A_SUB;  oc: $0400; ops:2;size: S_ALL;  o1:AF_IMM;     o2:AF_ALTNA        ),
  752.     (   i:A_SUBQ; oc: $5100; ops:2;size: S_ALL;  o1:AF_IMM;     o2:AF_ALT          ),
  753.     (   i:A_SUBX; oc: $9100; ops:2;size: S_ALL;  o1:AF_DN;      o2:AF_DN           ),
  754.     (   i:A_SUBX; oc: $9108; ops:2;size: S_ALL;  o1:AF_MMIND;   o2:AF_MMIND        ),
  755.  
  756.     (   i:A_SWAP; oc: $4840; ops:1;size: [S_W];  o1:AF_DN;      o2:0    ),
  757.     (   i:A_TAS;  oc: $4AC0; ops:1;size: [S_B];  o1:AF_ALTNA;   o2:0    ),
  758.     (   i:A_TRAP; oc: $4E40; ops:1;size: [S_NO]; o1:AF_IMM;     o2:0               ),
  759.     (   i:A_TRAPV;oc: $4E76; ops:0;size: [S_NO]; o1:0;          o2:0               ),
  760.     (   i:A_TST;  oc: $4A00; ops:1;size: S_ALL;  o1:AF_ALTNA;   o2:0               ),
  761.     (   i:A_UNLK; oc: $4E58; ops:1;size: [S_NO]; o1:AF_AN;      o2:0               ),
  762.     ( i:A_NONE)
  763.     );
  764.  
  765. {****************************************************************************
  766.                             Assembler Mnemoics
  767. ****************************************************************************}
  768.  
  769.    const
  770.      firstop = A_ABCD;
  771.      lastop = A_LABEL;
  772.  
  773.      mot_op2str : array[firstop..lastop] of string[10] =
  774.        { 68000 only instructions }
  775.        ('abcd','add', 'adda','addi','addq','addx','and','andi',
  776.        'asl','asr','bcc','bcs','beq','bge','bgt','bhi',
  777.        'ble','bls','blt','bmi','bne','bpl','bvc','bvs',
  778.        'bchg','bclr','bra','bset','bsr','btst','chk',
  779.        'clr','cmp','cmpa','cmpi','cmpm','dbcc','dbcs','dbeq','dbge',
  780.        'dbgt','dbhi','dble','dbls','dblt','dbmi','dbne','dbra',
  781.        'dbpl','dbt','dbvc','dbvs','dbf','divs','divu',
  782.        'eor','eori','exg','illegal','ext','jmp','jsr',
  783.        'lea','link','lsl','lsr','move','movea','movei','moveq',
  784.        'movem','movep','muls','mulu','nbcd','neg','negx',
  785.        'nop','not','or','ori','pea','rol','ror','roxl',
  786.        'roxr','rtr','rts','sbcd','scc','scs','seq','sge',
  787.        'sgt','shi','sle','sls','slt','smi','sne',
  788.        'spl','st','svc','svs','sf','sub','suba','subi','subq',
  789.        'subx','swap','tas','trap','trapv','tst','unlk',
  790.        'rte','reset','stop',
  791.        { MC68010 instructions }
  792.        'bkpt','movec','moves','rtd',
  793.        { MC68020 instructions }
  794.        'bfchg','bfclr','bfexts','bfextu','bfffo',
  795.        'bfins','bfset','bftst','callm','cas','cas2',
  796.        'chk2','cmp2','divsl','divul','extb','pack','rtm',
  797.        'trapcc','tracs','trapeq','trapf','trapge','trapgt',
  798.        'traphi','traple','trapls','traplt','trapmi','trapne',
  799.        'trappl','trapt','trapvc','trapvs','unpk',
  800.        { FPU Processor instructions - directly supported only. }
  801.        { IEEE aware and misc. condition codes not supported   }
  802.        'fabs','fadd',
  803.        'fbeq','fbne','fbngt','fbgt','fbge','fbnge',
  804.        'fblt','fbnlt','fble','fbgl','fbngl','fbgle','fbngle',
  805.        'fdbeq','fdbne','fdbgt','fdbngt','fdbge','fdnbge',
  806.        'fdblt','fdbnlt','fdble','fdbgl','fdbngl','fdbgle','fbdngle',
  807.        'fseq','fsne','fsgt','fsngt','fsge','fsnge',
  808.        'fslt','fsnlt','fsle','fsgl','fsngl','fsgle','fsngle',
  809.        'fcmp','fdiv','fmove','fmovem',
  810.        'fmul','fneg','fnop','fsqrt','fsub','fsgldiv',
  811.        'fsflmul','ftst',
  812.        'ftrapeq','ftrapne','ftrapgt','ftrapngt','ftrapge','ftrapnge',
  813.        'ftraplt','ftrapnlt','ftraple','ftrapgl','ftrapngl','ftrapgle',
  814.        'ftrapngle',
  815.        { Useful for assembly langage output }
  816.        { Protected instructions }
  817.        'cprestore','cpsave',
  818.        { FPU Unit protected instructions                    }
  819.        { and 68030/68851 common MMU instructions            }
  820.        { (this may include 68040 MMU instructions)          }
  821.        'frestore','fsave','pflush','pflusha','pload','pmove','ptest',
  822.        { Useful for assembly langage output }
  823.        '');
  824.  
  825.      mot_opsize2str : array[topsize] of string[2] =
  826.       ('','.b','.w','.l','.b','.b','.w','.d','.s','.x');
  827.  
  828.      mot_reg2str : array[R_NO..R_FPSR] of string[6] =
  829.       ('', 'd0','d1','d2','d3','d4','d5','d6','d7',
  830.        'a0','a1','a2','a3','a4','a5','a6','sp',
  831.        '-(sp)','(sp)+',
  832.        'ccr','fp0','fp1','fp2','fp3','fp4','fp5',
  833.        'fp6','fp7','fpcr','sr','ssp','dfc',
  834.        'sfc','vbr','fpsr');
  835.  
  836.      gas_opsize2str : array[topsize] of string[2] =
  837.       ('','.b','.w','.l','.b','.b','.w','.d','.s','.x');
  838.  
  839.      gas_reg2str : array[R_NO..R_FPSR] of string[6] =
  840.       ('', 'd0','d1','d2','d3','d4','d5','d6','d7',
  841.        'a0','a1','a2','a3','a4','a5','a6','sp',
  842.        '-(sp)','(sp)+',
  843.        'ccr','fp0','fp1','fp2','fp3','fp4','fp5',
  844.        'fp6','fp7','fpcr','sr','ssp','dfc',
  845.        'sfc','vbr','fpsr');
  846.  
  847.      gasPalmOS_reg2str : array[R_NO..R_FPSR] of string[6] =
  848.       ('', '%d0','%d1','%d2','%d3','%d4','%d5','%d6','%d7',
  849.        '%a0','%a1','%a2','%a3','%a4','%a5','%a6','%sp',
  850.        '-(%sp)','(%sp)+',
  851.        '%ccr','%fp0','%fp1','%fp2','%fp3','%fp4','%fp5',
  852.        '%fp6','%fp7','%fpcr','%sr','%ssp','%dfc',
  853.        '%sfc','%vbr','%fpsr');
  854.  
  855.      mit_opsize2str : array[topsize] of string[2] =
  856.       ('','b','w','l','b','b','w','d','s','x');
  857.  
  858.      mit_reg2str : array[R_NO..R_FPSR] of string[6] =
  859.       ('', 'd0','d1','d2','d3','d4','d5','d6','d7',
  860.        'a0','a1','a2','a3','a4','a5','a6','sp',
  861.        'sp@-','sp@+',
  862.        'ccr','fp0','fp1','fp2','fp3','fp4','fp5',
  863.        'fp6','fp7','fpcr','sr','ssp','dfc',
  864.        'sfc','vbr','fpsr');
  865.  
  866.  
  867.   implementation
  868.  
  869.     function reg2str(r : tregister) : string;
  870.  
  871.       const
  872.      a : array[R_NO..R_FPSR] of string[3] =
  873.       ('','D0','D1','D2','D3','D4','D5','D6','D7',
  874.        'A0','A1','A2','A3','A4','A5','A6','A7',
  875.       '-(SP)','(SP)+',
  876.        'CCR','FP0','FP1','FP2',
  877.        'FP3','FP4','FP5','FP6','FP7','FPCR','SR',
  878.        'SSP','DFC','SFC','VBR','FPSR');
  879.  
  880.       begin
  881.          if target_info.target=target_PalmOS then
  882.            reg2str:=gas_reg2str[r]
  883.          else
  884.            reg2str:=a[r];
  885.       end;
  886.  
  887.     function newreference(const r : treference) : preference;
  888.  
  889.       var
  890.      p : preference;
  891.  
  892.       begin
  893.      new(p);
  894.      p^:=r;
  895.      if assigned(r.symbol) then
  896.        p^.symbol:=stringdup(r.symbol^);
  897.      newreference:=p;
  898.       end;
  899.  
  900.     function lab2str(l : plabel) : string;
  901.  
  902.       begin
  903.          if (l=nil) or (l^.nb=0) then
  904. {$ifdef EXTDEBUG}
  905.            lab2str:='ILLEGAL'
  906.          else
  907.            lab2str:=target_info.labelprefix+tostr(l^.nb);
  908. {$else EXTDEBUG}
  909.            internalerror(2000);
  910.          lab2str:=target_info.labelprefix+tostr(l^.nb);
  911. {$endif EXTDEBUG}
  912.  
  913.          l^.is_used:=true;
  914.       end;
  915.  
  916.  
  917.     procedure reset_reference(var ref : treference);
  918.  
  919.       begin
  920.          with ref do
  921.         begin
  922.           index:=R_NO;
  923.           base:=R_NO;
  924.           segment:=R_DEFAULT_SEG;
  925.           offset:=0;
  926.           scalefactor:=1;
  927.           isintvalue:=false;
  928.           symbol:=nil;
  929.           direction := dir_none;
  930.         end;
  931.       end;
  932.  
  933.     procedure clear_reference(var ref : treference);
  934.  
  935.       begin
  936.      stringdispose(ref.symbol);
  937.      reset_reference(ref);
  938.       end;
  939.  
  940.     procedure getlabel(var l : plabel);
  941.  
  942.       begin
  943.      new(l);
  944.      l^.nb:=nextlabelnr;
  945.      l^.is_used:=false;
  946.      l^.is_set:=false;
  947.      l^.refcount:=0;
  948.      inc(nextlabelnr);
  949.       end;
  950.  
  951.     procedure freelabel(var l : plabel);
  952.  
  953.       begin
  954.      if (l<>nil) and (not l^.is_set) and (not l^.is_used) then
  955.        dispose(l);
  956.      l:=nil;
  957.       end;
  958.  
  959.     procedure setzerolabel(var l : plabel);
  960.  
  961.       begin
  962.      l^.nb:=0;
  963.      l^.is_used:=false;
  964.      l^.is_set:=false;
  965.      l^.refcount:=0;
  966.       end;
  967.  
  968.     procedure getzerolabel(var l : plabel);
  969.  
  970.       begin
  971.      new(l);
  972.      l^.nb:=0;
  973.      l^.is_used:=false;
  974.      l^.is_set:=false;
  975.      l^.refcount:=0;
  976.       end;
  977.  
  978.     procedure getlabelnr(var l : longint);
  979.  
  980.       begin
  981.      l:=nextlabelnr;
  982.      inc(nextlabelnr);
  983.       end;
  984.  
  985.     function newcsymbol(const s : string;l : longint) : pcsymbol;
  986.  
  987.       var
  988.      p : pcsymbol;
  989.  
  990.       begin
  991.      new(p);
  992.      p^.symbol:=strpnew(s);
  993.      p^.offset:=l;
  994.      newcsymbol:=p;
  995.       end;
  996.  
  997.     procedure disposecsymbol(p : pcsymbol);
  998.  
  999.       begin
  1000.       strdispose(p^.symbol);
  1001.       dispose(p);
  1002.       end;
  1003.  
  1004. {****************************************************************************
  1005.                  TAI68k
  1006.  ****************************************************************************}
  1007.  
  1008.     constructor tai68k.op_none(op : tasmop;_size : topsize);
  1009.  
  1010.       begin
  1011.      inherited init;
  1012.      typ:=ait_instruction;
  1013.      _operator:=op;
  1014.      op1t:=top_none;
  1015.      op2t:=top_none;
  1016.      op3t:=top_none;
  1017.      size:=_size;
  1018.  
  1019.      { the following isn't required ! }
  1020.      op1:=nil;
  1021.      op2:=nil;
  1022.      op3:=nil;
  1023.       end;
  1024.  
  1025.     constructor tai68k.op_reg(op : tasmop;_size : topsize;_op1 : tregister);
  1026.  
  1027.       begin
  1028.      inherited init;
  1029.      typ:=ait_instruction;
  1030.      _operator:=op;
  1031.      op1t:=top_reg;
  1032.      op2t:=top_none;
  1033.      op3t:=top_none;
  1034.      size:=_size;
  1035.      op1:=pointer(_op1);
  1036.  
  1037.      op2:=nil;
  1038.      op3:=nil;
  1039.       end;
  1040.  
  1041.     constructor tai68k.op_const(op : tasmop;_size : topsize;_op1 : longint);
  1042.  
  1043.  begin
  1044.      inherited init;
  1045.      typ:=ait_instruction;
  1046.      _operator:=op;
  1047.      op1t:=top_const;
  1048.      op2t:=top_none;
  1049.      op3t:=top_none;
  1050.      size:=_size;
  1051.      op1:=pointer(_op1);
  1052.  
  1053.      op2:=nil;
  1054.      op3:=nil;
  1055.   end;
  1056.  
  1057.  
  1058.  
  1059.     constructor tai68k.op_ref(op : tasmop;_size : topsize;_op1 : preference);
  1060.  
  1061.       begin
  1062.      inherited init;
  1063.      typ:=ait_instruction;
  1064.      _operator:=op;
  1065.      op2t:=top_none;
  1066.      op3t:=top_none;
  1067.      size:=_size;
  1068.      if _op1^.isintvalue then
  1069.        begin
  1070.           op1t:=top_const;
  1071.           op1:=pointer(_op1^.offset);
  1072.        end
  1073.      else
  1074.        begin
  1075.           op1t:=top_ref;
  1076.           op1:=pointer(_op1);
  1077.        end;
  1078.  
  1079.      op2:=nil;
  1080.      op3:=nil;
  1081.       end;
  1082.  
  1083.     constructor tai68k.op_loc(op : tasmop;_size : topsize;_op1 : tlocation);
  1084.  
  1085.       begin
  1086.      inherited init;
  1087.      typ:=ait_instruction;
  1088.      _operator:=op;
  1089.      op2t:=top_none;
  1090.      op3t:=top_none;
  1091.      size:=_size;
  1092.      if (_op1.loc=loc_register) or (_op1.loc=loc_cregister)  then
  1093.        begin
  1094.          op1t:=top_reg;
  1095.          op1:=pointer(_op1.register);
  1096.        end
  1097.      else
  1098.      if _op1.reference.isintvalue then
  1099.        begin
  1100.           op1t:=top_const;
  1101.           op1:=pointer(_op1.reference.offset);
  1102.        end
  1103.      else
  1104.        begin
  1105.           op1t:=top_ref;
  1106.           op1:=pointer(newreference(_op1.reference));
  1107.        end;
  1108.  
  1109.      op2:=nil;
  1110.      op3:=nil;
  1111.       end;
  1112.  
  1113.     constructor tai68k.op_reg_reg(op : tasmop;_size : topsize;_op1,_op2 : tregister);
  1114.  
  1115.       begin
  1116.      inherited init;
  1117.      typ:=ait_instruction;
  1118.      _operator:=op;
  1119.      op1t:=top_reg;
  1120.      op2t:=top_reg;
  1121.      op3t:=top_none;
  1122.      size:=_size;
  1123.      op1:=pointer(_op1);
  1124.      op2:=pointer(_op2);
  1125.  
  1126.      op3:=nil;
  1127.       end;
  1128.  
  1129.     constructor tai68k.op_reg_ref(op : tasmop;_size : topsize;_op1 : tregister;_op2 : preference);
  1130.  
  1131.       begin
  1132.      inherited init;
  1133.      typ:=ait_instruction;
  1134.      _operator:=op;
  1135.      op1t:=top_reg;
  1136.      op3t:=top_none;
  1137.      size:=_size;
  1138.      op1:=pointer(_op1);
  1139.  
  1140.      if _op2^.isintvalue then
  1141.        begin
  1142.           op2t:=top_const;
  1143.           op2:=pointer(_op2^.offset);
  1144.        end
  1145.      else
  1146.        begin
  1147.           op2t:=top_ref;
  1148.           op2:=pointer(_op2);
  1149.        end;
  1150.  
  1151.      op3:=nil;
  1152.       end;
  1153.  
  1154.     constructor tai68k.op_reg_loc(op : tasmop;_size : topsize;_op1 : tregister;_op2 : tlocation);
  1155.  
  1156.       begin
  1157.      inherited init;
  1158.      typ:=ait_instruction;
  1159.      _operator:=op;
  1160.      op1t:=top_reg;
  1161.      op3t:=top_none;
  1162.      size:=_size;
  1163.      op1:=pointer(_op1);
  1164.  
  1165.      if (_op2.loc=loc_register) or (_op2.loc=loc_cregister)  then
  1166.        begin
  1167.          op2t:=top_reg;
  1168.          op2:=pointer(_op2.register);
  1169.        end
  1170.      else
  1171.      if _op2.reference.isintvalue then
  1172.        begin
  1173.           op2t:=top_const;
  1174.           op2:=pointer(_op2.reference.offset);
  1175.        end
  1176.      else
  1177.        begin
  1178.           op2t:=top_ref;
  1179.           op2:=pointer(newreference(_op2.reference));
  1180.        end;
  1181.  
  1182.      op3:=nil;
  1183.       end;
  1184.  
  1185.     constructor tai68k.op_loc_reg(op : tasmop;_size : topsize;_op1 : tlocation;_op2 : tregister);
  1186.  
  1187.       begin
  1188.      inherited init;
  1189.      typ:=ait_instruction;
  1190.      _operator:=op;
  1191.      op2t:=top_reg;
  1192.      op3t:=top_none;
  1193.      size:=_size;
  1194.      op2:=pointer(_op2);
  1195.  
  1196.      if (_op1.loc=loc_register) or (_op1.loc=loc_cregister)  then
  1197.        begin
  1198.          op1t:=top_reg;
  1199.          op1:=pointer(_op1.register);
  1200.        end
  1201.      else
  1202.      if _op1.reference.isintvalue then
  1203.        begin
  1204.           op1t:=top_const;
  1205.           op1:=pointer(_op1.reference.offset);
  1206.        end
  1207.      else
  1208.        begin
  1209.           op1t:=top_ref;
  1210.           op1:=pointer(newreference(_op1.reference));
  1211.        end;
  1212.  
  1213.      op3:=nil;
  1214.       end;
  1215.  
  1216.     constructor tai68k.op_const_reg_reg(op : tasmop;_size : topsize;_op1 : longint;_op2 : tregister;_op3 : tregister);
  1217.  
  1218.       begin
  1219.      inherited init;
  1220.      typ:=ait_instruction;
  1221.      _operator:=op;
  1222.      op1t:=top_const;
  1223.      op2t:=top_reg;
  1224.      op3t:=top_reg;
  1225.      size:=_size;
  1226.      op1:=pointer(_op1);
  1227.      op2:=pointer(_op2);
  1228.      op3:=pointer(_op3);
  1229.       end;
  1230.  
  1231.   constructor tai68k.op_reg_const(op: tasmop; _size: topsize; _op1: tregister; _op2: longint);
  1232.    begin
  1233.     inherited init;
  1234.     typ := ait_instruction;
  1235.     _operator := op;
  1236.     op1t := top_reg;
  1237.     op2t := top_const;
  1238.     op3t := top_none;
  1239.     op1 := pointer(_op1);
  1240.     op2 := pointer(_op2);
  1241.     size := _size;
  1242.    end;
  1243.  
  1244.  
  1245.     constructor tai68k.op_reg_reg_reg(op : tasmop;_size : topsize;_op1 : tregister;_op2 : tregister;_op3 : tregister);
  1246.  
  1247.       begin
  1248.      inherited init;
  1249.      typ:=ait_instruction;
  1250.      _operator:=op;
  1251.      op1t:=top_reg;
  1252.      op2t:=top_reg;
  1253.      op3t:=top_reg;
  1254.      size:=_size;
  1255.      op1:=pointer(_op1);
  1256.      op2:=pointer(_op2);
  1257.      op3:=pointer(_op3);
  1258.       end;
  1259.  
  1260.     constructor tai68k.op_const_reg(op : tasmop;_size : topsize;_op1 : longint;_op2 : tregister);
  1261.  
  1262.       begin
  1263.      inherited init;
  1264.      typ:=ait_instruction;
  1265.      _operator:=op;
  1266.      op1t:=top_const;
  1267.      op2t:=top_reg;
  1268.      op3t:=top_none;
  1269.      size:=_size;
  1270.      op1:=pointer(_op1);
  1271.      op2:=pointer(_op2);
  1272.  
  1273.      op3:=nil;
  1274.       end;
  1275.  
  1276.     constructor tai68k.op_const_const(op : tasmop;_size : topsize;_op1,_op2 : longint);
  1277.  
  1278.       begin
  1279.      inherited init;
  1280.      typ:=ait_instruction;
  1281.      _operator:=op;
  1282.      op1t:=top_const;
  1283.      op2t:=top_const;
  1284.      op3t:=top_none;
  1285.      size:=_size;
  1286.      op1:=pointer(_op1);
  1287.      op2:=pointer(_op2);
  1288.  
  1289.      op3:=nil;
  1290.       end;
  1291.  
  1292.     constructor tai68k.op_const_ref(op : tasmop;_size : topsize;_op1 : longint;_op2 : preference);
  1293.  
  1294.       begin
  1295.      inherited init;
  1296.      typ:=ait_instruction;
  1297.      _operator:=op;
  1298.      op1t:=top_const;
  1299.      op3t:=top_none;
  1300.      size:=_size;
  1301.      op1:=pointer(_op1);
  1302.  
  1303.      if _op2^.isintvalue then
  1304.        begin
  1305.           op2t:=top_const;
  1306.           op2:=pointer(_op2^.offset);
  1307.        end
  1308.      else
  1309.        begin
  1310.           op2t:=top_ref;
  1311.           op2:=pointer(_op2);
  1312.        end;
  1313.  
  1314.      op3:=nil;
  1315.       end;
  1316.  
  1317.     constructor tai68k.op_const_loc(op : tasmop;_size : topsize;_op1 : longint;_op2 : tlocation);
  1318.  
  1319.       begin
  1320.      inherited init;
  1321.      typ:=ait_instruction;
  1322.      _operator:=op;
  1323.      op1t:=top_const;
  1324.      op3t:=top_none;
  1325.      size:=_size;
  1326.      op1:=pointer(_op1);
  1327.  
  1328.      if (_op2.loc=loc_register) or (_op2.loc=loc_cregister)  then
  1329.        begin
  1330.          op2t:=top_reg;
  1331.          op2:=pointer(_op2.register);
  1332.        end
  1333.      else
  1334.      if _op2.reference.isintvalue then
  1335.        begin
  1336.           op2t:=top_const;
  1337.           op2:=pointer(_op2.reference.offset);
  1338.        end
  1339.      else
  1340.        begin
  1341.           op2t:=top_ref;
  1342.           op2:=pointer(newreference(_op2.reference));
  1343.        end;
  1344.  
  1345.      op3:=nil;
  1346.       end;
  1347.  
  1348.     constructor tai68k.op_ref_reg(op : tasmop;_size : topsize;_op1 : preference;_op2 : tregister);
  1349.  
  1350.       begin
  1351.      inherited init;
  1352.      typ:=ait_instruction;
  1353.      _operator:=op;
  1354.      op2t:=top_reg;
  1355.      op3t:=top_none;
  1356.      size:=_size;
  1357.      op2:=pointer(_op2);
  1358.  
  1359.      if _op1^.isintvalue then
  1360.        begin
  1361.           op1t:=top_const;
  1362.           op1:=pointer(_op1^.offset);
  1363.        end
  1364.      else
  1365.        begin
  1366.           op1t:=top_ref;
  1367.           op1:=pointer(_op1);
  1368.        end;
  1369.  
  1370.      op3:=nil;
  1371.       end;
  1372.  
  1373.     constructor tai68k.op_ref_ref(op : tasmop;_size : topsize;_op1,_op2 : preference);
  1374.  
  1375.       begin
  1376.      inherited init;
  1377.      typ:=ait_instruction;
  1378.      _operator:=op;
  1379.      op3t:=top_none;
  1380.      size:=_size;
  1381.  
  1382.      if _op1^.isintvalue then
  1383.        begin
  1384.           op1t:=top_const;
  1385.           op1:=pointer(_op1^.offset);
  1386.        end
  1387.      else
  1388.        begin
  1389.           op1t:=top_ref;
  1390.           op1:=pointer(_op1);
  1391.        end;
  1392.  
  1393.      if _op2^.isintvalue then
  1394.        begin
  1395.           op2t:=top_const;
  1396.           op2:=pointer(_op2^.offset);
  1397.        end
  1398.      else
  1399.        begin
  1400.           op2t:=top_ref;
  1401.           op2:=pointer(_op2);
  1402.        end;
  1403.  
  1404.      op3:=nil;
  1405.       end;
  1406.  
  1407.     constructor tai68k.op_csymbol(op : tasmop;_size : topsize;_op1 : pcsymbol);
  1408.  
  1409.       begin
  1410.      inherited init;
  1411.      typ:=ait_instruction;
  1412.      _operator:=op;
  1413.      if (op=A_JSR) and
  1414.         (use_esp_stackframe) then
  1415.       Message(cg_e_stackframe_with_esp);
  1416.      op1t:=top_symbol;
  1417.      op2t:=top_none;
  1418.      op3t:=top_none;
  1419.      size:=_size;
  1420.      op1:=pointer(_op1);
  1421.  
  1422.      op2:=nil;
  1423.      op3:=nil;
  1424.       end;
  1425.  
  1426.     constructor tai68k.op_csymbol_reg(op : tasmop;_size : topsize;_op1 : pcsymbol;_op2 : tregister);
  1427.  
  1428.       begin
  1429.      inherited init;
  1430.      typ:=ait_instruction;
  1431.      _operator:=op;
  1432.      op1t:=top_symbol;
  1433.      op2t:=top_reg;
  1434.       op3t:=top_none;
  1435.      size:=_size;
  1436.      op1:=pointer(_op1);
  1437.      op2:=pointer(_op2);
  1438.  
  1439.      op3:=nil;
  1440.       end;
  1441.  
  1442.     constructor tai68k.op_csymbol_ref(op : tasmop;_size : topsize;_op1 : pcsymbol;_op2 : preference);
  1443.  
  1444.       begin
  1445.      inherited init;
  1446.      typ:=ait_instruction;
  1447.      _operator:=op;
  1448.      op1t:=top_symbol;
  1449.      op3t:=top_none;
  1450.      size:=_size;
  1451.      op1:=pointer(_op1);
  1452.  
  1453.      if _op2^.isintvalue then
  1454.        begin
  1455.           op2t:=top_const;
  1456.           op2:=pointer(_op2^.offset);
  1457.        end
  1458.      else
  1459.        begin
  1460.           op2t:=top_ref;
  1461.           op2:=pointer(_op2);
  1462.        end;
  1463.  
  1464.      op3:=nil;
  1465.       end;
  1466.  
  1467.     constructor tai68k.op_csymbol_loc(op : tasmop;_size : topsize;_op1 : pcsymbol;_op2 : tlocation);
  1468.  
  1469.       begin
  1470.      inherited init;
  1471.      typ:=ait_instruction;
  1472.      _operator:=op;
  1473.      op1t:=top_symbol;
  1474.      op3t:=top_none;
  1475.      size:=_size;
  1476.      op1:=pointer(_op1);
  1477.  
  1478.      if (_op2.loc=loc_register) or (_op2.loc=loc_cregister)  then
  1479.        begin
  1480.          op2t:=top_reg;
  1481.          op2:=pointer(_op2.register);
  1482.        end
  1483.      else
  1484.      if _op2.reference.isintvalue then
  1485.        begin
  1486.           op2t:=top_const;
  1487.           op2:=pointer(_op2.reference.offset);
  1488.        end
  1489.      else
  1490.        begin
  1491.           op2t:=top_ref;
  1492.           op2:=pointer(newreference(_op2.reference));
  1493.        end;
  1494.  
  1495.      op3:=nil;
  1496.       end;
  1497.  
  1498.    destructor tai68k.done;
  1499.  
  1500.      begin
  1501.     if op1t=top_symbol then
  1502.       disposecsymbol(pcsymbol(op1))
  1503.     else if op1t=top_ref then
  1504.       begin
  1505.          clear_reference(preference(op1)^);
  1506.          dispose(preference(op1));
  1507.       end;
  1508.     if op2t=top_symbol then
  1509.       disposecsymbol(pcsymbol(op2))
  1510.     else if op2t=top_ref then
  1511.       begin
  1512.          clear_reference(preference(op2)^);
  1513.          dispose(preference(op2));
  1514.       end;
  1515.     if op3t=top_symbol then
  1516.       disposecsymbol(pcsymbol(op3))
  1517.     else if op3t = top_ref then
  1518.       begin
  1519.          clear_reference(preference(op3)^);
  1520.          dispose(preference(op3));
  1521.       end;
  1522.     inherited done;
  1523.      end;
  1524.  
  1525.  
  1526.    constructor tai68k.op_ref_reglist(op: tasmop; _size : topsize; _op1: preference;_op2: tregisterlist);
  1527.    Begin
  1528.      Inherited Init;
  1529.       typ:=ait_instruction;
  1530.       _operator:=op;
  1531.       op2t:=top_reglist;
  1532.       op3t:=top_none;
  1533.       size:=_size;
  1534.      reglist := _op2;
  1535.  
  1536.       if _op1^.isintvalue then
  1537.         begin
  1538.            op1t:=top_const;
  1539.            op1:=pointer(_op1^.offset);
  1540.         end
  1541.       else
  1542.         begin
  1543.            op1t:=top_ref;
  1544.            op1:=pointer(_op1);
  1545.         end;
  1546.  
  1547.       op3:=nil;
  1548.    end;
  1549.  
  1550.  
  1551.    constructor tai68k.op_reglist_ref(op: tasmop; _size : topsize; _op1: tregisterlist; _op2: preference);
  1552.    Begin
  1553.      Inherited Init;
  1554.       typ:=ait_instruction;
  1555.  
  1556.       _operator:=op;
  1557.       reglist:=_op1;
  1558.  
  1559.      op1t:=top_reglist;
  1560.       op3t:=top_none;
  1561.       size:=_size;
  1562.  
  1563.       if _op2^.isintvalue then
  1564.         begin
  1565.            op2t:=top_const;
  1566.            op2:=pointer(_op2^.offset);
  1567.         end
  1568.       else
  1569.         begin
  1570.            op2t:=top_ref;
  1571.            op2:=pointer(_op2);
  1572.         end;
  1573.       op3:=nil;
  1574.    end;
  1575.  
  1576.  
  1577.  
  1578. {****************************************************************************
  1579.                               TAI_LABELED
  1580.  ****************************************************************************}
  1581.  
  1582.     constructor tai_labeled.init(op : tasmop; l : plabel);
  1583.  
  1584.       begin
  1585.          inherited init;
  1586.          typ:=ait_labeled_instruction;
  1587.          _operator:=op;
  1588.          _op1:=R_NO;
  1589.          lab:=l;
  1590.          lab^.is_used:=true;
  1591.          inc(lab^.refcount);
  1592.       end;
  1593.  
  1594.     constructor tai_labeled.init_reg(op : tasmop; l : plabel; reg: tregister);
  1595.  
  1596.       begin
  1597.          inherited init;
  1598.          typ:=ait_labeled_instruction;
  1599.          _op1:=reg;
  1600.          _operator:=op;
  1601.          lab:=l;
  1602.          lab^.is_used:=true;
  1603.          inc(lab^.refcount);
  1604.       end;
  1605.  
  1606.     destructor tai_labeled.done;
  1607.  
  1608.       begin
  1609.          dec(lab^.refcount);
  1610.          if lab^.refcount=0 then
  1611.            Begin
  1612.              lab^.is_used := False;
  1613.              If Not(lab^.is_set) Then
  1614.                Dispose(lab);
  1615.            End;
  1616.          inherited done;
  1617.       end;
  1618. {****************************************************************************
  1619.                                TAI_EXTENDED
  1620.  ****************************************************************************}
  1621.  
  1622.     constructor tai_extended.init(_value : bestreal);
  1623.  
  1624.       begin
  1625.          inherited init;
  1626.          typ:=ait_real_extended;
  1627.          value:=_value;
  1628.       end;
  1629.  
  1630.  
  1631. {****************************************************************************
  1632.                                TAI_COMP
  1633.  ****************************************************************************}
  1634.  
  1635.     constructor tai_comp.init(_value : bestreal);
  1636.  
  1637.       begin
  1638.          inherited init;
  1639.          typ:=ait_comp;
  1640.          value:=_value;
  1641.       end;
  1642.  
  1643. end.
  1644. {
  1645.   $Log: m68k.pas,v $
  1646.   Revision 1.1.1.1.2.1  1998/08/13 17:41:24  florian
  1647.     + some stuff for the PalmOS added
  1648.  
  1649.   Revision 1.1.1.1  1998/03/25 11:18:13  root
  1650.   * Restored version
  1651.  
  1652.   Revision 1.13  1998/03/10 01:17:20  peter
  1653.     * all files have the same header
  1654.     * messages are fully implemented, EXTDEBUG uses Comment()
  1655.     + AG... files for the Assembler generation
  1656.  
  1657.   Revision 1.12  1998/03/09 12:58:11  peter
  1658.     * FWait warning is only showed for Go32V2 and $E+
  1659.     * opcode tables moved to i386.pas/m68k.pas to reduce circular uses (and
  1660.       for m68k the same tables are removed)
  1661.     + $E for i386
  1662.  
  1663.   Revision 1.11  1998/03/06 00:52:24  peter
  1664.     * replaced all old messages from errore.msg, only ExtDebug and some
  1665.       Comment() calls are left
  1666.     * fixed options.pas
  1667.  
  1668.   Revision 1.10  1998/03/02 01:48:43  peter
  1669.     * renamed target_DOS to target_GO32V1
  1670.     + new verbose system, merged old errors and verbose units into one new
  1671.       verbose.pas, so errors.pas is obsolete
  1672.  
  1673.   Revision 1.9  1998/02/13 10:35:09  daniel
  1674.   * Made Motorola version compilable.
  1675.   * Fixed optimizer
  1676.  
  1677.   Revision 1.8  1998/02/12 11:50:13  daniel
  1678.   Yes! Finally! After three retries, my patch!
  1679.  
  1680.   Changes:
  1681.  
  1682.   Complete rewrite of psub.pas.
  1683.   Added support for DLL's.
  1684.   Compiler requires less memory.
  1685.   Platform units for each platform.
  1686.  
  1687.   Revision 1.7  1998/01/11 03:38:05  carl
  1688.   * bugfix op_reg_const , op3t was never initialized
  1689.  
  1690.   Revision 1.3  1997/12/09 13:46:42  carl
  1691.   + renamed pai_labeled68k --> pai_labeled
  1692.   + added extended size constant
  1693.  
  1694.   Revision 1.2  1997/11/28 18:14:37  pierre
  1695.    working version with several bug fixes
  1696.  
  1697.   Revision 1.1.1.1  1997/11/27 08:32:57  michael
  1698.   FPC Compiler CVS start
  1699.  
  1700.  
  1701.   Pre-CVS log:
  1702.  
  1703.   History:
  1704.       30th september 1996:
  1705.      + unit started
  1706.       15th october 1996:
  1707.      + tai386 added
  1708.      + some code from asmgen moved to this unit
  1709.       26th november 1996:
  1710.      + tai386_labeled
  1711.     ---------------------
  1712.       3rd september 1997:
  1713.      + unit started
  1714.       5th september 1997:
  1715.      + first version completed
  1716.      24 september 1997:
  1717.      + minor fixes regarding register conventions (CEC)
  1718.      26 september 1997:
  1719.      + added divs/muls tai68k constructor (CEC)
  1720.      + added mc68020 instruction types (CEC)
  1721.      + converted to work with v093 (CEC)
  1722.     4th october 1997:
  1723.     + version v95 (CEC)
  1724.     + added floating point flags (CEC)
  1725.     + added op_reg_const opcode for LINK instruction. (CEC)
  1726.     + added floating point branch / flags (CEC)
  1727.    2nd november 1997:
  1728.      + instruction set for the 68000/68020/common FPU/common MMU is
  1729.        now supposedely complete. (CEC).
  1730.     20th november 1997:
  1731.     * changed LOC_FPUREGISTER to LOC_FPU same as in i386.pas (PM)
  1732.  
  1733.   What is left to do:
  1734.     o  Create an opcode table to use in direct object output.
  1735.     o  Create an instruction template for MOVEM instruction.
  1736.  
  1737. }
  1738.